import { JCRequestOption, ServiceBase } from '../ServiceBase';
import { ApiPre } from '../../config';

const urlbase = `${ApiPre}/LookUp`;
const lturlbase = `${ApiPre}/MH_LOOKUPTEXT`;
const urls = {
  getLookUpValueList: `${urlbase}/GetLookUpValueList`,
  getLookupValueStructByTypeCode: `${urlbase}/GetLookupValueStructByTypeCode`,
  getLookUpExtendText: `${lturlbase}/GetLookUpExtendText`,
  vSaveLookUpValueExtendText: `${lturlbase}/VSaveLookUpValueExtendText`,
  getAllLookupValueTypeStruct: `${urlbase}/GetAllLookupValueTypeStruct`,
  saveLookUpType: `${urlbase}/SaveLookUpType`,
  saveLookUpValue: `${urlbase}/SaveLookUpValue`
};
export default class LookupService extends ServiceBase {
  getLookUpValueList(typeCode) {
    return this.request(urls.getLookUpValueList, { typeCode }, { cacheKey: `lookup_${typeCode}` });
  }

  getLookupValueStructByTypeCode(typeCode: string) {
    return this.request<any>(
      urls.getLookupValueStructByTypeCode,
      { typeCode },
      { cacheKey: `lookup_${typeCode}_relation` }
    );
  }

  getLookUpExtendText(obj) {
    // TableType tableType, int tableAutoId,string columnName, string lookupType, long lookupCode
    // 最多接收四个查询条件，最少接收第一个查询条件
    return this.request(urls.getLookUpExtendText, {
      paramModel: obj
    });
  }

  getAllLookupValueTypeStruct() {
    return this.request(urls.getAllLookupValueTypeStruct);
  }

  saveLookUpType(data) {
    return this.request(urls.saveLookUpType, {
      data
    });
  }

  saveLookUpValue(lookupvalue) {
    return this.request(urls.saveLookUpValue, {
      value: lookupvalue
    });
  }

  vSaveLookUpValueExtendText(texts, tableType, lookupType, columnName) {
    return this.request(urls.vSaveLookUpValueExtendText, {
      texts,
      tableType,
      lookupType,
      columnName
    });
  }
}
